package com.ruoyi.stock.service.impl;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.stock.domain.StockMarket;
import com.ruoyi.stock.mapper.StockMarketMapper;
import com.ruoyi.stock.service.IStockMarketService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 股票行情Service业务层处理
 *
 * @author ruoyi
 * @date 2025-08-05
 */
@Service
public class StockMarketServiceImpl implements IStockMarketService {
    @Resource
    private StockMarketMapper stockMarketMapper;

    /**
     * 查询股票行情
     *
     * @param id 股票行情主键
     * @return 股票行情
     */
    @Override
    public StockMarket selectStockMarketById(Long id)
    {
        return stockMarketMapper.selectStockMarketById(id);
    }

    /**
     * 查询股票行情列表
     * 
     * @param stockMarket 股票行情
     * @return 股票行情
     */
    @Override
    public List<StockMarket> selectStockMarketList(StockMarket stockMarket)
    {
        return stockMarketMapper.selectStockMarketList(stockMarket);
    }

    /**
     * 新增股票行情
     * 
     * @param stockMarket 股票行情
     * @return 结果
     */
    @Override
    public int insertStockMarket(StockMarket stockMarket)
    {
        stockMarket.setCreateTime(DateUtils.getNowDate());
        return stockMarketMapper.insertStockMarket(stockMarket);
    }

    @Override
    public AjaxResult importData(List<StockMarket> list, boolean updateSupport, Date stDate) {
        if (list != null && list.size() > 0) {
            //数据删除
            stockMarketMapper.delStockMarketByDate(stDate);
            Date nowDate = DateUtils.getNowDate();
            for (StockMarket data : list) {
                data.setCreateTime(nowDate);
                data.setStDate(stDate);
                stockMarketMapper.insertStockMarket(data);
            }
            return AjaxResult.success("导入成功,导入 " + list.size() + " 条数据 ！ ");

        }
        return AjaxResult.success("表中数据为空");
    }

    /**
     * 修改股票行情
     * 
     * @param stockMarket 股票行情
     * @return 结果
     */
    @Override
    public int updateStockMarket(StockMarket stockMarket)
    {
        stockMarket.setUpdateTime(DateUtils.getNowDate());
        return stockMarketMapper.updateStockMarket(stockMarket);
    }

    /**
     * 批量删除股票行情
     * 
     * @param ids 需要删除的股票行情主键
     * @return 结果
     */
    @Override
    public int deleteStockMarketByIds(Long[] ids)
    {
        return stockMarketMapper.deleteStockMarketByIds(ids);
    }

    /**
     * 删除股票行情信息
     * 
     * @param id 股票行情主键
     * @return 结果
     */
    @Override
    public int deleteStockMarketById(Long id)
    {
        return stockMarketMapper.deleteStockMarketById(id);
    }
}
